import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_outline_button.dart';
import 'package:kq_flutter_widgets/widgets/chart/base/kq_chart_model.dart';
import 'package:kq_flutter_widgets/widgets/chart/kq_chart_bar.dart';
import 'package:kq_flutter_widgets/widgets/chart/kq_chart_bar_model.dart';
import 'package:kq_flutter_widgets/widgets/chart/kq_chart_line_model.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

class ChartBarDemo extends StatefulWidget {
  const ChartBarDemo({super.key});

  @override
  State<ChartBarDemo> createState() => _ChartBarDemoState();
}

class _ChartBarDemoState extends State<ChartBarDemo> {
  List<ChartBarValue> chartList = [
    ChartBarValue(xValue: '周一', yValue: '20'),
    ChartBarValue(xValue: '周二', yValue: '40'),
    ChartBarValue(xValue: '周三', yValue: '30'),
    ChartBarValue(xValue: '周四', yValue: '60'),
    ChartBarValue(xValue: '周五', yValue: '50'),
    ChartBarValue(xValue: '周六', yValue: '90'),
    ChartBarValue(xValue: '周末', yValue: '70')
  ];
  List<ChartBarValue> chartList1 = [
    ChartBarValue(xValue: '周一', yValue: '30'),
    ChartBarValue(xValue: '周二', yValue: '30'),
    ChartBarValue(xValue: '周三', yValue: '20'),
    ChartBarValue(xValue: '周四', yValue: '40'),
    ChartBarValue(xValue: '周五', yValue: '70'),
    ChartBarValue(xValue: '周六', yValue: '60'),
    ChartBarValue(xValue: '周末', yValue: '80')
  ];

  List<ChartLineValue> chartList2 = [
    ChartLineValue(xValue: '周一', yValue: '50'),
    ChartLineValue(xValue: '周二', yValue: '30'),
    ChartLineValue(xValue: '周三', yValue: '39'),
    ChartLineValue(xValue: '周四', yValue: '88'),
    ChartLineValue(xValue: '周五', yValue: '55'),
    ChartLineValue(xValue: '周六', yValue: '99'),
    ChartLineValue(xValue: '周末', yValue: '25')
  ];

  bool isRefresh = false;
  KqChartBarModel model = KqChartBarModel(
    chartModel: KqChartModel(
        sizeHeight: 300.r,
        sizeWidth: 400.r,
        xRight: 30.r,
        isFixMaxY: true,
        unit: '单位:%',
        initialPointX: 12.r,
        xLeft: 30.r),
    chartBarArray: [],
    barWidths: [10.r, 10.r],
    barColors: [KqThemeColors.bgBlue, KqThemeColors.textYellow],
  );
  @override
  void initState() {
    super.initState();
    model.chartModel.isCurve = true;
    model.chartModel.isShowPoint = false;
    model.chartModel.xLeft = 50.r;
    model.chartModel.maxY = 100;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: KqHeadBar(
          headTitle: '图表',
        ),
        body: ListView(
          children: [
            KqChartBar(
              chartModel: model,
              height: 300.r,
              barList: [chartList1, chartList],
              lineList: [chartList2],
              backGroundColor: KqThemeColors.bgWhite,
              keyTag: "2",
            ),
            SizedBox(height: 10.r),
            KqOutlineButton(
                title: '刷新',
                onTap: () {
                  setState(() {});
                })
          ],
        ));
  }
}
